<?php

// 加载初始化文件
include '../init.php';

// 加载数据库连接文件
include DIR_CORE.'/MySQLDB.php';

// 接收传过来的 id 参数
$pub_id = $_GET['pub_id'];

// 每次通过列表页点击一次，楼主的 publish 表中 pub_hits 字段加 1
if ($_GET['action']) {
    $sql = "update publish set pub_hits = pub_hits + 1 where pub_id = $pub_id";
    my_query($sql);
}

// 提取楼主的帖子信息
$sql = "select * from publish left join user on pub_owner = user_name where pub_id = $pub_id";
$row = fetchRow($sql);

// 查询总记录数
$sql = "select count(*) from reply where rep_pub_id = $pub_id";
$rowCount = fetchColumn($sql);

// 载入配置文件
$config = include DIR_CONFIG.'/config.php';
// $rowsPerpage = $config['page']['rowsPerpage'];
// $maxnum = $config['page']['maxnum'];

// $url = "./show.php?pub_id=$pub_id&action=reply&";

// 计算总页数

// 调用函数，得到页码字符串
$strPage = 1;

// 提取回帖资源结果集
$pageNum = isset($_GET['pageNum']) ? $_GET['pageNum'] : 1;
// $offset = ($pageNum - 1) * $rowsPerpage;
// $rep_sql = "select * from reply left join user on rep_user = user_name where rep_pub_id = $pub_id order by rep_time desc limit $offset,$rowsPerpage";
$rep_sql = "select * from reply left join user on rep_user = user_name where rep_pub_id = $pub_id order by rep_time";
$rep_result = my_query($rep_sql);

// 提取当前帖子的回复数据
$num_sql = "select count(*) from reply where rep_pub_id = $pub_id";
$rep_num = fetchColumn($num_sql);

// 每次通过列表页点击一次，楼主的 publish 表中 pub_hits 字段加 1
// if (!$_GET['action']) {
//     $sql = "update publish set pub_hits = pub_hits + 1 where pub_id = $pub_id";
//     my_query($sql);
// }

// 加载视图文件
include DIR_VIEW.'/show.html';

?>
